<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商列表</title>
<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/resources/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ex/ligerGrid.showFilter.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ex/ligerFilterEx.js" type="text/javascript"></script>
<script src="/resources/js/jsF7.js" type="text/javascript"></script>
<script src="/resources/js/selectData.js" type="text/javascript"></script>
<script type="text/javascript">
    var bool_data = [
                     { id: '1', value: '1', text: '是' },
                     { id: '0', value: '0', text: '否' }
                 ];
        var $grid;
        var form;
        var manager;
        $(function (){
        	
        	

          	 $("#layout_tree_grid").ligerLayout({
          		    leftWidth: 200,
                  centerBottomHeight:180,
                   height: '100%'
          		//onHeightChanged: f_heightChanged 
                  
                  
               });
           	 var menu = $.ligerMenu({ width: 120, items:
           	        [	
           	         	{ text: '添加新节点', click: addTreeItem, icon: 'add' },
           	         	{ text: '更新选择节点', click: updateTreeItem, icon: 'edit' },
           	            { text: '删除选择节点', click: delTreeItem, icon: 'delete' } 
           	        ]
           	        });
           		//树形
           		manager = $("#tree1").ligerTree({
           			 url:"/supplierClassification/supplierClassificationList",
           			 checkbox: false,
           			 isExpand: 2,
           	         idFieldName :'uuid',
           	         slide:false,
           	         parentIDFieldName:'parentId',
           	         textFieldName:'name',
           	         nodeWidth : 300,
           	         isLeaf:function(data){
           	        	 if(data.children){
           	        		 data.leaf = false;
           	        		 return false;
           	        	 }else{
           	        		 data.leaf = true;
           	        		 return true;
           	        	 }
           	         },
           	         onClick:onClick,
           	         onContextmenu: function (node, e){
           	             menu.show({ top: e.pageY, left: e.pageX });
           	             return false;
           	         }
           	     });
        	//创建查询对象
        	/* form = $("#form2").ligerForm({
            	  inputWidth: 150, labelWidth: 80, space: 40,
                  fields: [ 
                      { label: "供应商名", name: "userName", minWidth:100, type: "text", validate: {minlength: 5 } },
                      { label: "是否可用", name: "status", minWidth:100, type: "select",editor: {data:bool_data}}
                  ]
            });  */
            //创建表格对象 高级查询editor 识别编辑器有：combobox date number string
            $grid = $("#maingrid").ligerGrid({
                columns: [
                { name: 'uuid', hide:true,type:"text"},
                { display: '编码', name: 'number', minWidth: 140,type:"text"},
                { display: '名称', name: 'name', minWidth: 140,type:"text"},
               /*  { display: "业务分析码", name: "businessNum", minWidth:100, type: "text"}, */
               { display: "所属采购员", name: "subBuyer.uuid",minWidth:100, type: "popup",textField:"subBuyer.trueName",
									   editor: {type: "popup",
								        grid: getSysUserGrid(true),
								        valueField:'uuid',
								        textField: 'trueName',
								        parms :{date:new Date().getTime()},
								        realTimeLoad:true
									 }   
								},
                /* { display: "内部供应商", name: "inerCustomer", minWidth:100, type: "text"},
                { display: "内部公司", name: "inerCompany", minWidth:100, type: "text"},
                { display: "上级供应商", name: "superCustomer", minWidth:100, type: "text"}, */
               /*  { display: "供应商性质", name: "supplierProper", minWidth:100, type: "text"}, */
               /*  { display: "供应商性质", name: "supplierProper.uuid", minWidth:100, type: "popup",textField:"supplierProper.name",
             	   editor: {type: "popup",
	                       grid: getSuppliersNatureGrid(true),
	                       valueField:'uuid',
	                       textField: 'name',
	                       parms :{date:new Date().getTime()},
	                       realTimeLoad:true
	              	 }   
                }, */
                { display: "供应商性质", name: "supplierNature", minWidth:100,  type: "select",
				                	render:function(item){
				            			try{
				                    		return getCombobxTextByValue(supplier_nature_data,item.supplierNature);
				            			}catch(e){
				            				return null;
				            			}
				                	},editor: {type:'combobox',options:{data:supplier_nature_data,
					valueField: 'value',textField: 'text'}
				}}, 
                { display: "工商注册号", name: "industrialNum", minWidth:100, type: "text"},
                { display: "营业执照", name: "tradingNum", minWidth:200, type: "text"},
                { display: "经营许可证", name: "manageNum", minWidth:100, type: "text"},
                { display: "税务登记号", name: "taxNumber", minWidth:150, type: "text"},
                { display: "法人代表", name: "legalPerson", minWidth:100, type: "text"},
                { display: "行业", name: "industry", minWidth:100, type: "text"},
                { display: "国家", name: "country", minWidth:100, type: "text",editor: {}},
                { display: "省份", name: "province", minWidth:100, type: "text",editor: {}},
                { display: "城市(区)", name: "city", minWidth:100, type: "text",editor: {}},
                { display: "地区(县)", name: "district", minWidth:100, type: "text",editor: {}},
                { display: "邮政编码", name: "zipCode", minWidth:100, type: "text"},
                { display: "税种", name: "taxType", minWidth:100, type: "text"},
                { display: "税率", name: "taxRate", minWidth:100, type: "text"},
              /*   { display: "开票类型", name: "makeType", minWidth:100, type: "text"}, */
                { display: "开票类型", name: "makeType", minWidth:100,  type: "select",
                	render:function(item){
            			try{
                    		return getCombobxTextByValue(billing_type,item.makeType);
            			}catch(e){
            				return null;
            			}
                	},editor: {type:'combobox',options:{data:billing_type,
						valueField: 'value',textField: 'text'}
					}},
                { display: "地址", name: "address", newline: true, type: "text",minWidth:170},
                { display: "会计联系人", name: "finance.accountingPerson", minWidth:100, type: "text"}, 
				{ display: "联系人职务", name: "finance.personPosition", minWidth:100, type: "text"}, 
				{ display: "办公电话", name: "finance.phone", minWidth:100, type: "text"}, 
				{ display: "手机", name: "finance.mobile", minWidth:100, type: "text"}, 
				/* { display: "邮件", name: "finance.mail", minWidth:100, type: "text"},  */
				/* { display: "开户银行", name: "finance.openBank", minWidth:100, type: "text"}, */
				{ display: "开户银行", name: "finance.openBank.uuid", minWidth:100, type: "popup",textField:"finance.openBank.name",
                	   editor: {type: "popup",
	                       grid: getBankGrid(true),
	                       valueField:'uuid',
	                       textField: 'name',
	                       parms :{date:new Date().getTime()},
	                       realTimeLoad:true
	              	 }   
                 },
				{ display: "银行账号", name: "finance.bankAccount", minWidth:100, type: "text"},
				/* { display: "币别", name: "finance.currency", minWidth:100, type: "text"}, */
				{ display: "币别", name: "finance.currency.uuid", minWidth:100, type: "popup",textField:"finance.currency.name",
                	   editor: {type: "popup",
	                       grid: getCurrencyGrid(true),
	                       valueField:'uuid',
	                       textField: 'name',
	                       parms :{date:new Date().getTime()},
	                       realTimeLoad:true
	              	 }   
                 },
				{ display: "账户名称", name: "finance.accountName", minWidth:100, type: "text"},
				{ display: "会计联系人", name: "finance.accountingPerson", minWidth:100, type: "text"}, 
				{ display: "联系人职务", name: "finance.personPosition", minWidth:100, type: "text"}, 
				{ display: "办公电话", name: "finance.phone", minWidth:100, type: "text"}, 
				{ display: "手机", name: "finance.mobile", minWidth:100, type: "text"}, 
				/* { display: "邮件", name: "finance.mail", minWidth:100, type: "text"},  */
				/* { display: "开户银行", name: "finance.openBank", minWidth:100, type: "text"}, */
				{ display: "开户银行", name: "finance.openBank.uuid", minWidth:100, type: "popup",textField:"finance.openBank.name",
                	   editor: {type: "popup",
	                       grid: getBankGrid(true),
	                       valueField:'uuid',
	                       textField: 'name',
	                       parms :{date:new Date().getTime()},
	                       realTimeLoad:true
	              	 }   
                 },
				{ display: "银行账号", name: "finance.bankAccount", minWidth:100, type: "text"},
				/* { display: "币别", name: "finance.currency", minWidth:100, type: "text"}, */
				{ display: "币别", name: "finance.currency.uuid", minWidth:100, type: "popup",textField:"finance.currency.name",
                	   editor: {type: "popup",
	                       grid: getCurrencyGrid(true),
	                       valueField:'uuid',
	                       textField: 'name',
	                       parms :{date:new Date().getTime()},
	                       realTimeLoad:true
	              	 }   
                 },
				{ display: "账户名称", name: "finance.accountName", minWidth:100, type: "text"},
				{ display: "创建人", name: "createUser.uuid", type: 'popup',minWidth:100,textField: 'createUser.trueName',
	            	 editor: {type: "popup",
	                     grid: getSysUserGrid(true),
	                     valueField:'uuid',
	                     textField: 'trueName',
	                     parms :{date:new Date().getTime()},
	                     realTimeLoad:true
	            	 }
	            },
	            { display: "创建日期", name: "createDate", minWidth:100, type: "date",editor:{type:'date'}}
                ],
                autoFilter:true,
                width: '100%', pageSizeOptions: [5, 10, 15, 20], height: '100%',pageSize:20,
                checkbox: true,headerRowHeight:22, rowHeight:22, rownumbers:true,
                url:'/supplier/listData',
                onLoadData:onloadData,
                onDblClickRow:onDblClickRow,
                toolbar: { items: [
                                   { text: '新增', click: addClick, icon: 'add' },
                                   { line: true },
                                   { text: '修改', click: alertClick, icon: 'modify' },
                                   { line: true },
                                   { text: '删除', click: delClick, icon: 'delete' }
                                   ]
                                   }
            });

        });
        //添加
        function addClick(item){
        	var node = manager.getSelected();
        	if(node &&node.data && node.data.uuid){
        		f_addTab('addSupplier','新增供应商',"/supplier/addSupplier?supplierClassificationUuid="+node.data.uuid+"");
        	}else{
        		f_addTab('addSupplier','新增供应商','/supplier/addSupplier');
        	}
        	
        }
        //双击事件(查看)
        function onDblClickRow(data, rowindex, rowobj){
        	f_addTab('viewSupplier','查看供应商','/supplier/viewSupplier?uuid='+data.uuid);

        }
        
        //删除
        function delClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1){
        		$.ligerDialog.error("请至少选择一行数据");
        		return;
        	}
    		$.ajax({ 
    			url: '/supplier/delSupplier', 
    			data:{rows : JSON.stringify(rows)}, 
    			type: "post", 
    			dataType:'json',
    			cache : false, 
    			success: function(data){
    				$.ligerDialog.success(data.message,'信息',function(){
    		        	 $grid.reload();
    				});
    			},
    	        error: function (message) {
    	            $.ligerDialog.error("删除失败");
    	        }
    	});
        }
        //修改
        function alertClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1 || rows.length != 1){
        		$.ligerDialog.error("请选择一条要修改的数据");
        		return;
        	}
        	f_addTab('alterSupplier','修改供应商','/supplier/alterSupplier?uuid='+rows[0].uuid);
        }
        
        //查询
        function viewClick(){
        	//重新加载grid
        	 $grid.reload();
        }
        
      //获取数据前添加过滤条件
      function onloadData(){
    	/*   var cond = JSON.stringify(form.getData());
    	  this.options.parms.cond= cond;
    	  this.options.parms.temp= true; */
    	/*   applay(this.options.parms, [{ name: "cond", value: cond, temp: true }]); */
    	 //this.set('parms', [{ name: "cond", value: cond, temp: true }]);
      }
  	  //添加窗口
      function f_addTab(tabid,text, url){
  		this.parent.f_addTab(tabid,text, url);
      } 
  	  
      function updateTreeItem(){
   		 var node = manager.getSelected();
   		 if(!node){
   			alert("请先选择节点");
          	return;
   		 }
          if( node.data.uuid == ''){
          	alert("请先保存节点");
          	return;
          }else{
        	  openNewWindow('修改商品分类:',400,450,"/supplierClassification/addSupplierClassification?uuid="+node.data.uuid+"",node,'UPDATE');
          }
   	  }
       //添加节点
       function addTreeItem(){
           var node = manager.getSelected();
          /*  if( node.data.uuid == ''){
           	alert("请先保存节点");
           	return;
           }else{ */
           openNewWindow('新增商品分类:',400,450,'/supplierClassification/addSupplierClassification',node,'NEW');
           //}
           /* $.ajax({ 
       		url: '/categories/addCategories', 
       		data:{},
       		type: "post",
       		dataType:'json',
       		cache : false, 
       		success: function(obj){
       			var sn = '0000';
       			if(obj){
       				sn = obj.sn;
       			}
       		    var nodes = [];
       		    nodes.push({number:sn, name: $("#txtNode").val(),parentId: node.data.uuid,level:node.data.level+1});
       		    if (node)
       		        manager.append(node.target, nodes); 
       		    else
       		        manager.append(null, nodes);
       		},
               error: function (message) {
               	$.ligerDialog.error('保存失败');
               }
       		}); */
        }
        
        //删除节点
        function delTreeItem(){
       	 var node = manager.getSelected();
       	 if(node.data.parentId == '' || node.data.parentId == null){
       		 $.ligerDialog.question('根节点不能删除');
       		 return;
       	 }
       	 $.ligerDialog.confirm('你确定是要删除数据', function (yes) {		 
       		 if(yes){
       			 if( node.data.children == null){
       				 $.ajax({ 
       						url: '/supplierClassification/delSupplierClassifications', 
       						data:{uuid : node.data.uuid}, 
       						type: "post",
       		     		   	dataType:'json',
       						cache : false, 
       						success: function(obj){
       							if(obj.code=='SUCCESS'){
      								$.ligerDialog.success(obj.message);
          		                    manager.clear();
          		                    manager.setData(obj.data);
          		                    manager.remove(node.target);
      	                    	}else{
      	                    		 $.ligerDialog.error(json.message,"系统提示");
      	                    	}
       						},
       		                error: function (message) {
       		                	$.ligerDialog.error('删除失败');
       		                }
       			 		});
       			 }else{
       				 $.ligerDialog.question('请先删除子菜单');
       			 }
       		 }
       	 });
        }
        
        //点击事件
        function onClick(note){
     	if(note.data.parentId){
     		if($grid.options.parms){
     			$grid.options.parms.rigidCondition = "supplierClassification.uuid='"+note.data.uuid+"'";
     		}else{
     			$grid.set('parms', {rigidCondition:"supplierClassification.uuid='"+note.data.uuid+"'"});
     		}
     	}else{
     		if($grid.options.parms){
     			delete $grid.options.parms.rigidCondition;
     		}
     	}
     	$grid.loadData();
        }

        function f_heightChanged(options)
        {
            if ($grid)
         	   $grid.addHeight(options.diff);
            if (manager && options.middleHeight - 24 > 0)
         	   manager.setHeight(options.middleHeight - 24);
        }
        
        
        function openNewWindow(title,height,width,url,data,action_type){
     	   console.log(data);
        	$.ligerDialog.open({
    			height:height,
                width: width,
                title : title,
                url: url, 
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false,
                data:data,
                action_type:action_type
            });
        }
        
        function reloadTree(){
     	   manager.reload();
        }
        
        function appendOrUpdateNode(status,target,node){
       	  var nodes = [];
   		    nodes.push(node);
       	  if(status=='0'){
       		  manager.append(target, nodes);
       	  }else if(status=='2'){
       		  manager.update(target,node);
       	  }
         }
    </script>
</head>
<body  style="padding:10px">
    <div id="layout_tree_grid">
            <div position="left" title="供应商分类">
            	<div class="tree" style="height:100%; overflow: scroll;"> 
		            <ul id="tree1"></ul> 
		        </div> 
            </div>
            <div position="center" title="供应商列表" style="height:100%;">
               <div id="maingrid"></div> 
            </div>  
     </div>
   <div style="display:none;">
</body>
</html>
